<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <link rel="shortcut icon" href="#" />
    <link rel="stylesheet" href="./用户1&2.css">
</head>

<body>
    <div class="big_box">
        <div class="header">
            <img class="p"
                src="https://chibaoshaitaiyang-1316184616.cos.ap-beijing.myqcloud.com/%E7%99%BD%E8%89%B2%E9%80%8F%E6%98%8E%20%281%29.png"
                alt="">
        </div>
        <div class="words">
            欢迎使用<br>
            <div class="words2"><strong>云顶研学系统</strong></div>
        </div>

        <div class="section_One">
            <img src="https://chibaoshaitaiyang-1316184616.cos.ap-beijing.myqcloud.com/399cef91_E811112_03972d39.jpg"
                alt="" width="390px" height="450px">
        </div>
        <div class="main">
            <div class="title">欢迎注册</div>
            <div class="id">
                <input id="user_id" type="text" placeholder="学号:" size="40"><br>
            </div>
            <div class="invite">
                <input id="invitation_code" type="text" placeholder="邀请码:" size="40px" height="5px"><br>
            </div>
            <div class="name">
                <div><input id="user_name" type="text" placeholder="姓名:" size="15"><br></div>
                <div><input id="direction" type="text" placeholder="方向:" size="15"><br></div>
            </div>
            <div class="age"><input id="phase_num" type="text" placeholder="期数:" size="40"><br></div>
            <div class="ser"> <input type="password" id="ipt" name="passwd" placeholder="请输入密码" size="32px"
                    onkeyup="checkpassword()">
                <span class="many">(8-16位)</span>
            </div>

            <div class="more">
                <input type="password" id="repw" name="repasswd" placeholder="请再次输入密码" size="32px"
                    onkeyup="checkpassword()">
            </div>
            <span id="tishi" style=" display:block;margin-left:-200px; margin-top:-25px;"></span>
            <button id="btn">立&nbsp&nbsp即&nbsp&nbsp注&nbsp&nbsp册</button>
        </div>

    </div>
    <script>
        function checkpassword() {
            var password = document.getElementById("ipt").value;
            var repassword = document.getElementById("repw").value;
            if (password == repassword) {
                document.getElementById("tishi").innerHTML = "<font color='green'>两次密码输入一致</font>";
                // document.getElementById("submit").disabled = false;

            } else {
                document.getElementById("tishi").innerHTML = "<font color='red'>两次输入密码不一致!</font>";
                // document.getElementById("submit").disabled = true;
            }
        }
        var many = document.querySelector('.many');
        var ipt = document.querySelector('#ipt');

        ipt.onblur = function () {
            if (ipt.value.length < 8 || ipt.value.length > 16) {
                many.className = 'many wrong';
                many.innerHTML = '格式错误';

            } else {
                many.className = 'many right';
                many.innerHTML = '格式正确';

            }
        }



        var btn = document.getElementById("btn");
        btn.onclick = function () {
            var user_id = document.getElementById("user_id").value;
            var invitation_code = document.getElementById("invitation_code").value;
            var user_name = document.getElementById("user_name").value;
            var direction = document.getElementById("direction").value;
            var phase_num = document.getElementById("phase_num").value;
            var password = document.getElementById("ipt").value;
            console.log("user_id")
            console.log("invitation_code")
            console.log("user_name")
            console.log("111")
            if (!user_id || !invitation_code || !user_name || !direction || !phase_num || !password) {
                alert('请将信息填写完整')
                return
            }
            axios({
                url: "http://q2ax8vel.shenzhuo.vip:50295/register/",
                method: "POST",
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                data: {
                    user_id: `${user_id}`,
                    invitation_code: `${invitation_code}`,
                    user_name: `${user_name}`,
                    direction: `${direction}`,
                    phase_num: `${phase_num}`,
                    password: `${password}`
                } 
            }).then(function (result) {
                if (result.data.result == -1) {
                    alert("不在云顶书院")
                }
                if (result.data.result == -2) {
                    alert("邀请码错误")
                }
                if (result.data.result == -3) {
                    alert("用户已存在")
                }
            })
                    // .catch(function (error) {
                    //     alert("立即注册失败");
                    //     console.log(error);
                    // })
            // window.location.href = "../用户3.html";

        }

    </script>
</body>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <link rel="shortcut icon" href="#" />
    <link rel="stylesheet" href="./用户1&2.css">
</head>

<body>
    <div class="big_box">
        <div class="header">
            <img class="p"
                src="https://chibaoshaitaiyang-1316184616.cos.ap-beijing.myqcloud.com/%E7%99%BD%E8%89%B2%E9%80%8F%E6%98%8E%20%281%29.png"
                alt="">
        </div>
        <div class="words">
            欢迎使用<br>
            <div class="words2"><strong>云顶研学系统</strong></div>
        </div>

        <div class="section_One">
            <div class="title">欢迎注册</div>
            <div class="id">
                <input id="user_id" type="text" placeholder="学号:" size="40"><br>
            </div>
            <div class="invite">
                <input id="invitation_code" type="text" placeholder="邀请码:" size="40px" height="5px"><br>
            </div>
            <div class="name">
                <div><input id="user_name" type="text" placeholder="姓名:" size="15"><br></div>
                <div><input id="direction" type="text" placeholder="方向:" size="15"><br></div>
            </div>
            <div class="age"><input id="phase_num" type="text" placeholder="期数:" size="40"><br></div>
            <div class="ser"> <input type="password" id="ipt" name="passwd" placeholder="请输入密码" size="32px"
                    onkeyup="checkpassword()">
                <span class="many">(8-16位)</span>
            </div>

            <div class="more">
                <input type="password" id="repw" name="repasswd" placeholder="请再次输入密码" size="32px"
                    onkeyup="checkpassword()">
            </div>
            <span id="tishi" style=" display:block;margin-left:-200px; margin-top:-25px;"></span>
            <button id="btn">立即注册</button>
        </div>
    </div>
    <script>
        function checkpassword() {
            var password = document.getElementById("ipt").value;
            var repassword = document.getElementById("repw").value;
            if (password == repassword) {
                document.getElementById("tishi").innerHTML = "<font color='green'>两次密码输入一致</font>";
                // document.getElementById("submit").disabled = false;

            } else {
                document.getElementById("tishi").innerHTML = "<font color='red'>两次输入密码不一致!</font>";
                // document.getElementById("submit").disabled = true;
            }
        }
        var many = document.querySelector('.many');
        var ipt = document.querySelector('#ipt');

        ipt.onblur = function () {
            if (ipt.value.length < 8 || ipt.value.length > 16) {
                many.className = 'many wrong';
                many.innerHTML = '格式错误';

            } else {
                many.className = 'many right';
                many.innerHTML = '格式正确';

            }
        }



        var btn = document.getElementById("btn");
        btn.onclick = function () {
            var user_id = document.getElementById("user_id").value;
            var invitation_code = document.getElementById("invitation_code").value;
            var user_name = document.getElementById("user_name").value;
            var direction = document.getElementById("direction").value;
            var phase_num = document.getElementById("phase_num").value;
            var password = document.getElementById("ipt").value;
            console.log("user_id")
            console.log("invitation_code")
            console.log("user_name")
            console.log("111")

            axios({
                url: "http://4ussc82j.shenzhuo.vip:47189/register/",
                method: "POST",
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                data: {
                    user_id: `${user_id}`,
                    invitation_code: `${invitation_code}`,
                    user_name: `${user_name}`,
                    direction: `${direction}`,
                    phase_num: `${phase_num}`,
                    password: `${password}`
                }
            })
                .then(function (response) {
                    alert("立即注册成功");
                    console.log(response);
                })
                .catch(function (error) {
                    alert("立即注册失败");
                    console.log(error);
                });
            window.location.href = "../用户3.html";

        }

    </script>
</body>

</html>